<script setup>
import {onMounted, ref} from 'vue'
import {getBannerAPI} from '@/api/home.js'

const bannerList = ref([])
const getBannerList = async () => {
  const res = await getBannerAPI()
  console.log(res)
  bannerList.value = res.result
}
onMounted(() => {
  getBannerList()
})
</script>

<template>
  <div class="home-banner">
    <el-carousel height="500px">
      <!--这里将获取到的list进行遍历-->
      <el-carousel-item v-for="item in bannerList" :key="item.id">
        <!--我们可以看到，我们只需要将img的src属性和list.imgUrl进行双向绑定即可-->
        <img
            :src="item.imgUrl"
            alt="">
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<style scoped lang='scss'>
.home-banner {
  width: 1240px;
  height: 500px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 98;

  img {
    width: 100%;
    height: 500px;
  }
}
</style>